<?php

/* TODO: extend the login class as CMF_LOGIN and set the correct variables there */

class ArtistLogin extends Controller{
	var $default_redirect = '';
	var $pwd_file = '';
	var $pwd_table = 'Artist_Users';
	var $pwd_crypt = CMF_PASSWORD_ENCRYPTION;
	
	function ArtistLogin(){
		parent::Controller();
		$this->load->helper('url');
		$this->load->library('session');
		$this->default_redirect = CMF_URL . 'artist';
	}
	
	function index(){
		$data = array(
			'user' => '',
			'message' => ''
		);
		if( isset($_POST['user']) && isset($_POST['password']) ){
			$this->load->library('login_lib', array('file' => $this->pwd_file, 'table' => $this->pwd_table, 'encrypt' => $this->pwd_crypt, 'role' => 'artist', 'extra_fields' => array('active' => 1)));
			if( $this->login_lib->doLogin($_POST['user'], $_POST['password']) ){
				$redirect = $this->session->userdata('redirect');
				if( $redirect ){
					$this->session->unset_userdata('redirect');
					redirect($redirect);
				}else{
					redirect($this->default_redirect);
				}
			}else{
				$data['user'] = $_POST['user'];
				$data['message'] = 'Invalid user/password combination';
			}
		}
		$this->session->set_userdata('login_url', CMF_PREFIX . 'artistlogin');
		$this->load->view(CMF_LOGIN_VIEW, $data);
	}
}

?>